package com.xiaoquan.myspring.SpringIOC.step2.factory.support;

import com.xiaoquan.myspring.SpringIOC.step2.beans.BeanDefintion;
import com.xiaoquan.myspring.SpringIOC.step2.factory.config.SingletonBeanRegistry;
import org.springframework.beans.BeansException;

/**
 * @Author: 周海权
 * @CreateTime: 2024-08-30
 * @Description:
 * @Version: 1.0
 */
public abstract class AbstractBeanFactory extends DefaultSingletonBeanRegistry implements SingletonBeanRegistry {

    @Override
    public Object getSingleton(String name) throws BeansException {
        Object bean = getSingleton(name);
        if (bean != null) {
            return bean;
        }

        BeanDefintion beanDefinition = getBeanDefinition(name);
        return createBean(name, beanDefinition);
    }

    protected abstract BeanDefintion getBeanDefinition(String beanName) throws BeansException;

    protected abstract Object createBean(String beanName, BeanDefintion beanDefinition) throws BeansException;


}

